package com.rocky_tech.framework.struts.listener;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import com.rocky_tech.framework.xmlprase.Struts_config;
import com.rocky_tech.framework.xmlprase.XmlBean;

@WebListener
public class ActionListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("信息：系统已经注销！");
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		ServletContext context = arg0.getServletContext();
		String xmlPath = context.getInitParameter("struts-config");
		String tomcatPath = context.getRealPath("\\");

		try {
			//System.out.println("-------------"+tomcatPath+xmlPath+"-----------------");
			//解析struts-config.xml
			Map<String ,XmlBean> map = Struts_config.struts_xml(tomcatPath+xmlPath);
			context.setAttribute("struts",map);
		} catch (Exception e) {
			System.out.println("严重：struts-config.xml文件加载错误！");
			e.printStackTrace();
		}
		System.out.println("信息：系统已经加载完成！");
	}

}
